import {
  Controller,
  Post,
  UseInterceptors,
  UploadedFile,
  UseGuards,
} from '@nestjs/common';
import { ApiTags, ApiBearerAuth, ApiConsumes } from '@nestjs/swagger';
import { AuthGuard } from '@/guards';
import { FileUtils } from '@/utils';
import { FileStoragePath } from '@/enum';

@ApiTags('upload')
@Controller('resources/upload')
export class UploadController {
  @ApiBearerAuth()
  @ApiConsumes('multipart/form-data')
  @UseGuards(AuthGuard)
  @UseInterceptors(
    FileUtils.singleFileUploader(
      'file',
      ['image'],
      FileStoragePath.LIBRARY_IMAGES,
    ),
  )
  @Post('image')
  imageUploader(@UploadedFile() file: Express.Multer.File) {
    return file.path;
  }
}
